﻿using System;
using UnityEngine;

namespace Framework
{
    public class ViewEvent : MonoBehaviour, IEventTrigger, IModuleEventTrigger, IView
    {
        private IEventDispatcher _eventDispatcher;
        private IModuleEventDispatcher _moduleEventDispatcher;

        protected void SetEventDispatcher(IEventDispatcher eventDispatcher, IModuleEventDispatcher moduleEventDispatcher)
        {
            _eventDispatcher = eventDispatcher;
            _moduleEventDispatcher = moduleEventDispatcher;
        }
        
        public void TriggerEvent(string eventName)
        {
            _eventDispatcher.TriggerEvent(eventName);
        }

        public void TriggerEvent<T>(string eventName, T arg1)
        {
            _eventDispatcher.TriggerEvent(eventName, arg1);
        }

        public void TriggerEvent<T, U>(string eventName, T arg1, U arg2)
        {
            _eventDispatcher.TriggerEvent(eventName, arg1, arg2);
        }

        public void TriggerEvent<T, U, V>(string eventName, T arg1, U arg2, V arg3)
        {
            _eventDispatcher.TriggerEvent(eventName, arg1, arg2, arg3);
        }

        public void TriggerEvent<T, U, V, W>(string eventName, T arg1, U arg2, V arg3, W arg4)
        {
            _eventDispatcher.TriggerEvent(eventName, arg1, arg2, arg3, arg4);
        }

        public void TriggerModuleEvent(string eventName)
        {
            _moduleEventDispatcher.TriggerModuleEvent(eventName);
        }

        public void TriggerModuleEvent<T>(string eventName, T arg1)
        {
            _moduleEventDispatcher.TriggerModuleEvent(eventName, arg1);
        }

        public void TriggerModuleEvent<T, U>(string eventName, T arg1, U arg2)
        {
            _moduleEventDispatcher.TriggerModuleEvent(eventName, arg1, arg2);
        }

        public void TriggerModuleEvent<T, U, V>(string eventName, T arg1, U arg2, V arg3)
        {
            _moduleEventDispatcher.TriggerModuleEvent(eventName, arg1, arg2, arg3);
        }

        public void TriggerModuleEvent<T, U, V, W>(string eventName, T arg1, U arg2, V arg3, W arg4)
        {
            _moduleEventDispatcher.TriggerModuleEvent(eventName, arg1, arg2, arg3, arg4);
        }

        public virtual void Dispose()
        {
            //TODO:移除这个View的Event
        }
    }
}